<%include file="header.html"%>
<%include file="top.html"%>
<%include file="left.html"%>

<style>

select {
    width: 90px;
}

input[type=checkbox].ace, input[type=radio].ace {
opacity: 0;
position: absolute;
z-index: 12;
width: 18px;
height: 38px;
cursor: pointer;
}

.table-header {
background-color: #307ecc;
color: #FFF;
font-size: 14px;
line-height: 35px;
padding-left: 12px;
margin-bottom: 1px;
padding-bottom:2px;
}

.comments {  
 width:100%;/*自动适应父布局宽度*/  
 overflow:auto;  
 word-break:break-all; 
 border-color:#307ecc;
 float:left;
 }
</style>
<div class="main-content">
<div class="breadcrumbs" id="breadcrumbs"><script
	type="text/javascript">
	try {
		ace.settings.check('breadcrumbs', 'fixed')
	} catch (e) {
	}
</script>

<ul class="breadcrumb">
	<li><i class="icon-home home-icon"></i> <a
		href="index.php">首页</a></li>
</ul>
<!-- .breadcrumb --></div>

<div class="page-content">
<div class="col-xs-12">
<div class="alert alert-info">
<form class="form-horizontal" role="form">
<div class="row">

<div class="col-sm-2">
<div class="row">
<label class="col-sm-6 control-label no-padding-right" for="form-field-5">游戏</label>
<div class="col-sm-3"><select id="selectGame">
	<option value="" >游戏</option>
	<%if $selectGames%> <%foreach from = $selectGames key = key item = value%>
	<%if $nowGame == $value %>
	<option value="<%$value%>" selected><%$value%></option>
	<%else%>
	<option value="<%$value%>"><%$value%></option>
	<%/if%> <%/foreach%> <%/if%>
</select>
</div>
</div>
</div>


<div class="col-sm-2">
<div class="row">
<label class="col-sm-6 control-label no-padding-right" for="form-field-5">活动</label>
<div class="col-sm-3">
<select id="activity">
	<option value="" >活动</option>
	<%if $activitys%> <%foreach from = $activitys key = key item = value%>
	<%if $nowActivity == $value %>
	<option value="<%$value%>" selected><%$value%></option>
	<%else%>
	<option value="<%$value%>"><%$value%></option>
	<%/if%> <%/foreach%> <%/if%>
</select>
</div>
</div>
</div>

<div class="col-sm-2">
<div class="row">
<label class="col-sm-6 control-label no-padding-right" for="form-field-5">服</label>
<div class="col-sm-3">
<select style="width:110px;" id="platform">
	<option value="" >服</option>
	<%if $platforms%> <%foreach from = $platforms key = key item = value%>
	<%if $nowPlatform == $value %>
	<option value="<%$value%>" selected><%$value%></option>
	<%else%>
	<option value="<%$value%>"><%$value%></option>
	<%/if%> <%/foreach%> <%/if%>
</select>
</div>
</div>
</div>


<div class="col-sm-2">
<div class="row">
	<label class="col-sm-6 control-label no-padding-right" for="form-field-5"></label>
	<button class="width-10 btn btn-sm btn-primary" type="button" onClick="configure();">配置</button> 
</div>
</div>

</div>
</form>
</div>
</div>

<div  class="col-xs-12" style="display:<%$display%>">
<div   id ="servers2" class="table-header">
<form  style="cursor:pointer;" id="formname"  method="post" action="index.php?mod=ActivityConf&do=show&action=1&upload=1&game=<%$nowGame%>&platform=<%$nowPlatform%>&activity=<%$nowActivity%>" enctype="multipart/form-data">
	<button class="btn btn-primary" onclick="document.getElementById('f').click();return false;"  style="color:white;cursor:pointer">
	<a href="#"><font class="white"><i class="icon-cloud-upload"></i>&nbsp;上传excel</font> </a> 
	</button>
	
	<span style="color:yellow"> <%$result%> </span>
	
	<input   type="file" id="f" name ="file" onchange="$('#formname').submit();" name="f" style="position:absolute; filter:alpha(opacity=0); opacity:0; font-size:1px;cursor:pointer;z-index:2" />
</form>

</div>
<div style="width:100%;height:650px;overflow-x:auto;overflow-y:auto;" id="servers"  class="table-responsive">

	<table id="sample-table-1" class="table table-striped table-bordered table-hover">
											<thead>
												<tr>
													<th>文件名</th>
													<th>文件类型</th>
													<th>游戏</th>
													<th>活动名称</th>
													<th>活动id</th>
													<th>大小</th>
													<th >上次修改</th>
													<th >修改者</th>
													<th >创建时间</th>
													<th >创建者</th>
													<th>操作</th>
												</tr>
											</thead>

											<tbody>
											<%if $rootFile%>
											<%foreach from = $rootFile key = fileId item = rootFile%>
												<tr>
													<td width="200px;">
													<div class="visible-md visible-lg visible-sm visible-xs action-buttons">
													 <!--  <i class="icon-file-alt bigger-130"></i> -->
													 	<img width="12px;" src="<%$staticUrl%>jsonImg/excel.png"/>
													  <%$rootFile.excel_name%>
													</div>
													</td>
													<td ><%$rootFile.node_type%></td>
													<td ><%$rootFile.node_game%></td>
													<td ><%$rootFile.node_activity_id%></td>
													<td ><%$rootFile.activityId%></td>
													<td ><%$rootFile.node_size%></td>
													<td ><%$rootFile.node_update_time%></td>
													<td ><%$rootFile.node_update_user%></td>
													<td ><%$rootFile.node_create_time%></td>
													<td ><%$rootFile.node_create_user%></td> 
													<td>
														<div class="visible-md visible-lg visible-sm visible-xs action-buttons">
															<!--  
															<a class="red" href="javascript:if(confirm('确认删除吗?'))window.location='index.php?mod=Node&do=delete&node_id=<%$rootFile.node_id%>&bucketId=<%$rootFile.bucket_id%>&parentNodeId=<%$rootFile.node_parent_node%>'" >
																<i class="icon-trash bigger-130"></i>&nbsp;删除
															</a>
															-->
															<a class="green" target="_blank" href="index.php?mod=ActivityConf&do=preview&type=excel&node_id=<%$rootFile.node_id%>" >
																<i class="icon-eye-open bigger-130"></i>&nbsp;预览excel
															</a>
															<a class="green" target="_blank" href="index.php?mod=ActivityConf&do=preview&type=xml&node_id=<%$rootFile.node_id%>" >
																<i class="icon-eye-open bigger-130"></i>&nbsp;预览xml
															</a>
															<a class="green" target="_blank" href="index.php?mod=ActivityConf&do=preview&type=lua&node_id=<%$rootFile.node_id%>" >
																<i class="icon-eye-open bigger-130"></i>&nbsp;预览lua
															</a>
															&nbsp;
															<a class="red"  href="index.php?mod=ActivityConf&do=downLoad&type=excel&node_id=<%$rootFile.node_id%>" >
																<i class="icon-download bigger-130"></i>&nbsp;下载excel
															</a>
															&nbsp;
															<a class="red"  href="index.php?mod=ActivityConf&do=downLoad&type=xml&node_id=<%$rootFile.node_id%>" >
																<i class="icon-download bigger-130"></i>&nbsp;下载xml
															</a>
															&nbsp;
															&nbsp;
															<a class="red"  href="index.php?mod=ActivityConf&do=downLoad&type=lua&node_id=<%$rootFile.node_id%>" >
																<i class="icon-download bigger-130"></i>&nbsp;下载lua
															</a>
															&nbsp;
															<!-- 
															javascript:if(confirm('确认生效到服务器吗?'))window.location='index.php?mod=ActivityConf&do=upOnline&node_id=<%$rootFile.node_id%>'
															 -->
															<a class="green"   onclick="javascript:if(confirm('确认生效到服务器吗?'))shengxiao(<%$rootFile.node_id%>);" >
																<i class="icon-arrow-up bigger-130"></i>&nbsp;生效
															</a>
														</div>
													</td>			
												</tr>
												
												<%/foreach%>												
												<%/if%>												
											</tbody>
										</table>
</div>
</div>

</div>
<!-- /.page-content --></div>
<!-- /.main-content -->
<script type="text/javascript">
	
//全选
$("#selectAll").click(function(){
	 $("#servers :checkbox").prop("checked", true); 
}); 
// 反选
$("#unSelect").click(function () {//全不选  
     $("#servers :checkbox").prop("checked", false); 
});  	
	
	jQuery(function($) {
		$('.date-picker').datepicker({
			autoclose : true
		}).next().on(ace.click_event, function() {
			$(this).prev().focus();
		});

		var oTable1 = $('#sample-table-2').dataTable({
			"aoColumns" : [ {
				"bSortable" : false
			}, {
				"bSortable" : false
			}, {
				"bSortable" : false
			}
			]
		});
		

	});
	
	/**
	     配置活动跳转
	*/
	function configure() {
		var game = $('#selectGame').val();
		var platform = $('#platform').val();
		var activity = $('#activity').val();
		
		if(!game) {
			alert("请选择游戏");
		} else if(!platform) {
			alert("请选择服");
		}  else if(!activity) {
			alert("请选择活动");
		} else {
			url = "index.php?mod=ActivityConf&do=show&action=1&game="+game+"&platform="+platform+"&activity="+activity;
			window.location.href= url;
		}
	}
	
	function formSubmit() {
		var game = $('#selectGame').val();
		var platform = $('#platform').val();
		var timeout = $('#timeout').val();
		var command = $('#command').val();
		
		var servers=''; 
		$("input[name='checkboxs']:checked").each(function(){ 
			servers += $(this).val()+','; 
		});
		
		if (!game || !timeout || !command || !servers) {
			alert('请将信息填写完整！');
		} else {
			url = "index.php?mod=Shell&do=showServerList&game="+game+"&platform="+platform+"&servers="+servers+"&command="+command+"&timeout="+timeout;
			window.location.href = url;
		}
	}
	
	/*
	更新xml
	*/
	function formSubmitXML() {
		var game = $('#selectGame').val();
		var platform = $('#platform').val();
		var timeout = $('#timeout').val();
		
		var command = "sh /data/java/shell/upXml_" + game + ".sh";
		
		var servers=''; 
		$("input[name='checkboxs']:checked").each(function(){ 
			servers += $(this).val()+','; 
		});
		
		if  (!timeout || !servers) {
			alert('请选择服！');
		} else {
			url = "index.php?mod=Shell&do=showServerList&game="+game+"&platform="+platform+"&servers="+servers+"&command="+command+"&timeout="+timeout;
			window.location.href = url;
		}

	}
	
	/**
	生效到服务器
	*/
	function shengxiao(node_id) {
		var param = {};	
		param['mod'] 	  	 = "ActivityConf";
		param['do'] 	  	 = "shengxiao";
		param['game'] 	  	 = $('#selectGame').val();
		param['platform'] 	 = $('#platform').val();
		param['activity'] 	 = $('#activity').val();
		param['node_id'] 	 = node_id;
		
		param['downLoadUrl'] = "<%$urlHead%>/index.php?mod=ActivityConf&do=downLoad&type=xml&node_id="+node_id;
		param['downLoadUrlLua'] = "<%$urlHead%>/index.php?mod=ActivityConf&do=downLoad&type=lua&node_id="+node_id;
		
		if(!param['game']) {
			alert("请选择游戏");
			return ;
		}
		if(!param['platform']) {
			alert("请选择服");
			return ;
		}
		
		$.ajax({
    	    type: "POST",
			url: "index.php",
			data: param,
			dataType: 'html',
			success: function(data) {
				var dataObj = eval("(" + data + ")");//转换为json对象
				var code = dataObj.status;
				if (code == 1) {
					alert("生效成功");
				} else if (code == 3) {
					alert("服务器连接失败");
				} else {
					alert("生效失败");
				}
			}
		});
	}
	
	// 重启服
	function restartServer() {
		var game = $('#selectGame').val();
		var platform = $('#platform').val();
		var timeout = $('#timeout').val();
		
		var command = "";
		if(game  == "zsgj") {
			command = "sh /data/java/gua01_test_sever/trunk/jar/restart.sh gua01 9096 9001 restart";
		} else {
			command = "sh /data/java/legend_test_sever/trunk/jar/restart.sh legend 9095 9000 restart";
		}
		
		var servers=''; 
		$("input[name='checkboxs']:checked").each(function(){ 
			servers += $(this).val()+','; 
		});
		
		if  (!timeout || !servers) {
			alert('请选择服！');
		} else {
			url = "index.php?mod=Shell&do=showServerList&game="+game+"&platform="+platform+"&servers="+servers+"&command="+command+"&timeout="+timeout;
			window.location.href = url;
		}
	}
	
	 window.onload = function(){
	    var select = document.getElementById('selectGame');
	    select.onchange = function(){
	        // 更改值后执行的代码
	       var gameName = jQuery("#selectGame  option:selected").text();
	       var game = $('#selectGame').val();
		   url = "index.php?mod=ActivityConf&do=getPlatfromByGame&game="+game;
			$.ajax({
	    	    type: "POST",
				url: url,
				data: "",
				dataType: 'html',
				success: function(data) {					
					var dataObj = eval("(" + data + ")");//转换为json对象
					if(dataObj == null) {
						$("#platform").empty();
						$("#platform").append('<option value="" id="selectPlatform">服</option>');
					}
					
					$("#platform").empty();
					$("#platform").append('<option value="" id="selectPlatform2">服</option>');
					for(var i=0;i<dataObj.length;i++){
						$("#platform").append("<option value='"+dataObj[i]+"' >"+dataObj[i]+"</option>"+"<br/>");
					}
				}
		    });
			
			url2 = "index.php?mod=ActivityConf&do=getActivityByGame&game="+game;
			$.ajax({
	    	    type: "POST",
				url: url2,
				data: "",
				dataType: 'html',
				success: function(data) {					
					var dataObj = eval("(" + data + ")");//转换为json对象
					if(dataObj == null) {
						$("#activity").empty();
						$("#activity").append('<option value="" >活动</option>');
					}
					
					$("#activity").empty();
					$("#activity").append('<option value="" >活动</option>');
					for(var i=0;i<dataObj.length;i++){
						$("#activity").append("<option value='"+dataObj[i]+"' >"+dataObj[i]+"</option>"+"<br/>");
					}
				}
		    });
	   	}
	    
	    
	    // 选择平台
	    var selectPlatform = document.getElementById('platform');
	    /*
	    selectPlatform.onchange = function(){
	        var platformName = jQuery("#platform  option:selected").text();
	        var game = $('#selectGame').val();
	        var platform = $('#platform').val();
			url = "index.php?mod=Shell&do=showServerList&game="+game+"&platform="+platform;
			window.location.href = url; 
	    }
	    */
	} 
	
</script>
<%include file="footer.html"%>

